package com.housekeeping.housekeeping.wxPay.dao.impl;

import com.housekeeping.housekeeping.utils.DBManager;
import com.housekeeping.housekeeping.wxPay.dao.PayDao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class PayDaoImpl implements PayDao {
    @Override
    public int creatWXPayOrder(String aid, Long oid,int money) throws SQLException {
        int res=0;
        Connection connection = DBManager.getConnection();
        String sql="insert into pay_order(id,aid,money) VALUES(?,?,?)";
        PreparedStatement ps = connection.prepareStatement(sql);
        ps.setObject(1,oid);
        ps.setString(2,aid);
        ps.setInt(3,money);
        res=ps.executeUpdate();
        DBManager.close(ps,connection);
        return res;
    }

    @Override
    public int updateStatus(Long orderId, int status) throws SQLException {
        int res=0;
        Connection connection = DBManager.getConnection();
        String sql="update pay_order set status=? where id=?";
        PreparedStatement ps = connection.prepareStatement(sql);
        ps.setInt(1,status);
        ps.setObject(2,orderId);
        res=ps.executeUpdate();
        DBManager.close(ps,connection);
        return res;
    }
}
